<?php
class Message extends CI_controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('message_model');
	}
	
	public function index($p=0){
		 
		$n = $this->message_model->get_message();
//		print_r($n->num_rows());
		$this->load->library('pagination');
$this->load->library('haaway');
print_r($this->haaway->show_me('whw w whhwhw w'));

		 $config['base_url'] = '/message/p';; 
		  $config['total_rows'] = $n->num_rows();
		  $config['per_page'] = 2;
		  $config['full_tag_open'] = '<p>';
		  $config['full_tag_close'] = '</p>';

		  $config['first_link'] = 'First';
		  $config['first_tag_open'] = '<div>';
		  $config['first_tag_close'] = '</div>';
		  $config['last_link'] = 'Last';
		  $config['last_tag_open'] = '<div>';
		  $config['last_tag_close'] = '</div>';
		  $this->pagination->initialize($config);

		$data['msg'] = $this->message_model->page_message($p, $config['per_page']);

		$data['title'] = '留言分页';

		$data['pageinfo'] = $this->pagination->create_links();
//		print_r($this->pagination->show_my('hahawww---www'));
//print_r($data);
		$this->load->view('templates/header', $data);
		$this->load->view('messages/index', $data);
		$this->load->view('templates/footer');

	}
	public function view($id){
		$n = $this->message_model->getby_msg($id);
		$data['title'] = $n['title'];
		$data['msg'] = $n;
		$this->load->view('templates/header', $data);
		$this->load->view('messages/view', $data);
		$this->load->view('templates/footer');

	}

	public function create(){
//		var_dump($this->input->post());

		$this->load->helper('form');
  		$this->load->library('form_validation');
		$data['title'] = '创建留言';

		$this->form_validation->set_rules('title', 'Title', 'required');

		if( $this->form_validation->run() === FALSE ){
			$this->load->view('templates/header', $data);
			$this->load->view('messages/create' );
			$this->load->view('templates/footer');
		}else{
			$this->message_model->set_msg();
			$this->load->view('messages/suc');
		}
		
	}
}
/* End of file message.php */
/* Location: ./application/model/message.php */
